package com.pay.service.service.mq;

import com.pay.common.constant.PayConstant;
import com.pay.service.pojo.PayOrder;
import com.pay.service.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;

/**
 * @author qzz
 * @site www.qzz.com
 * @create 2020-06-20 12:44
 */
@Service
public class BaseService {
    @Autowired
    private IOrderService orderService;

    public int baseUpdateStatus4Complete(String orderId) {

        PayOrder payOrder = new PayOrder();
        payOrder.setPayOrderId(orderId);
        payOrder.setStatus(""+PayConstant.PAY_STATUS_COMPLETE);
       /* PayOrderExample example = new PayOrderExample();
        PayOrderExample.Criteria criteria = example.createCriteria();
        criteria.andPayOrderIdEqualTo(payOrderId);
        criteria.andStatusEqualTo(PayConstant.PAY_STATUS_SUCCESS);*/
        if(orderService.saveOrUpdate(payOrder)){
            return 1;
        }
        return 0;
    }

    public int baseUpdateNotify(String orderId, byte count) {
        PayOrder newPayOrder = new PayOrder();
        newPayOrder.setNotifyCount(new Integer(count));
        newPayOrder.setLastNotifyTime(BigInteger.valueOf(System.currentTimeMillis()));
        newPayOrder.setPayOrderId(orderId);
        if(orderService.updateById(newPayOrder)){
            return 1;
        }
        return 0;
    }
}
